
#include <windows.h>

void ConGotoXY( int x, int y )
{
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    HANDLE hConsole = GetStdHandle( STD_OUTPUT_HANDLE );
    GetConsoleScreenBufferInfo( hConsole, &csbi );

    COORD pt;
    if ( ( x < 0 || x > csbi.dwSize.X ) ||
         ( y < 0 || x > csbi.dwSize.Y ) ) return;

    pt.X = x;
    pt.Y = y;
    SetConsoleCursorPosition( hConsole, pt );
}

int ConGetColor()
{
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    HANDLE hConsole = GetStdHandle( STD_OUTPUT_HANDLE );
    GetConsoleScreenBufferInfo( hConsole, &csbi );

    return csbi.wAttributes;
}

void ConSetColor( int color )
{
    WORD mc = (WORD)(color & 0x000000FF);
    WORD clr = (WORD)(ConGetColor() & 0x0000FF00);
    clr = clr + mc;
    HANDLE hConsole = GetStdHandle( STD_OUTPUT_HANDLE );
    SetConsoleTextAttribute( hConsole, clr );
}

void ConGetCurPos( int &x, int &y )
{
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    HANDLE hConsole = GetStdHandle( STD_OUTPUT_HANDLE );
    GetConsoleScreenBufferInfo( hConsole, &csbi );

    x = csbi.dwCursorPosition.X;
    y = csbi.dwCursorPosition.Y;
}

